<?php
class Test
{
	public function testTableList(VOTableList $param, VOUserSession $userSession = NULL){
		
		$dbi = new Dbi();
		if($dbi->mysqli == FALSE && PRODUCTION == FALSE){
			return $dbi->error;
		}
		
		$query = "SELECT COUNT(id) FROM test_list";
		$param->totalRecord = $dbi->fetchSingleItemCRUD($userSession, $query);
		$query = "SELECT * FROM test_list";
		$className = "VOTestCrud";
		$result = $dbi->fetchTableObjectsCRUD($userSession, $param, $query, $className);
		return $result;
	}

	public function testSave(VOTestCrud $saveItem, VOUserSession $userSession = NULL){
		$dbi = new Dbi();
		if($dbi->mysqli == FALSE && PRODUCTION == FALSE){
			return $dbi->error;
		}
		
		if(empty($saveItem->id)){
			$query = "INSERT INTO test_list(label, value) VALUES('$saveItem->label', $saveItem->value)";
		} else {
			$query = "UPDATE test_list SET id=$saveItem->id, label='$saveItem->label', value='$saveItem->value' WHERE id=$saveItem->id";
		}
		
		$result = $dbi->executeCRUD($userSession, $query);
		return $result;
	}
}
?>